<?php

class Curl {
    
    public static $user_cookie_file;

    public function __construct() {
        
    }

    public static function get($url) {
        self::$user_cookie_file = $_SERVER['DOCUMENT_ROOT'] . '/cookies.txt';
        $cc = curl_init($url);
        curl_setopt($cc, CURLOPT_URL, $url);
        curl_setopt($cc, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($cc, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16");
        curl_setopt($cc, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($cc, CURLOPT_COOKIEJAR, self::$user_cookie_file);
        curl_setopt($cc, CURLOPT_COOKIEFILE, self::$user_cookie_file);
        $html = curl_exec($cc);
        if($html === false)
            echo curl_error($cc);
        curl_close($cc);
        return $html;
    }

    public static function post($url, $data) {
        //���� ������
    }

}

class MCurl {

   public static function multiget($urls) {   
        $threads = 10;
        $useragent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16";

        $i = 0;
        for ($i = 0; $i < count($urls); $i = $i + $threads) {
            $urls_pack[] = array_slice($urls, $i, $threads);
        }
        foreach ($urls_pack as $pack) {
            $mh = curl_multi_init();
            unset($conn);
            foreach ($pack as $i => $url) {
                $conn[$i] = curl_init(trim($url));
                curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($conn[$i], CURLOPT_TIMEOUT, "10");
                curl_setopt($conn[$i], CURLOPT_USERAGENT, $useragent);
                curl_multi_add_handle($mh, $conn[$i]);
            }
            do {
                $n = curl_multi_exec($mh, $active);
                usleep(100);
            } while ($active);
            foreach ($pack as $i => $url) {
                $result[] = curl_multi_getcontent($conn[$i]);
                curl_close($conn[$i]);
            }
            curl_multi_close($mh);
        }
        return $result;
    }

}

?>
